package com.example.evensystem.model.entity

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.Update
import java.sql.Time
import java.util.Date

@Entity(
    tableName = "monthlywork", primaryKeys = ["month", "id"],
    foreignKeys = arrayOf(
        ForeignKey(
            entity = MonthPlan::class,
            parentColumns = ["month"],
            childColumns = ["month"],
            onDelete = ForeignKey.CASCADE,
            onUpdate = ForeignKey.CASCADE
        )
    )
)
data class MonthlyWork(

    //月份
    val month: String,
    //工号
    val id: String,
    //迟到次数
    var lateTimes: Int,
    //早退次数
    var leftEarlyTimes: Int,
    //剩余天数
    var leftDates: Int,
    //已工作天数
    var workedDates: Int
)

@Dao
interface MonthlyWorkDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(monthlyWork: MonthlyWork)

    @Delete
    fun delete(monthlyWork: MonthlyWork)

    @Update
    fun update(monthlyWork: MonthlyWork)

    @Query("select* from monthlywork where month=:month and id=:id")
    fun find(month: String, id: String): List<MonthlyWork>
}